<?php
namespace App\Http\Controllers\Test;
use App\Http\Classes\Compress;
use App\Http\Classes\IM\IMCurl;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;

/**
 * Created by PhpStorm.
 * User: Celebration-Grey
 * Date: 2017/4/12
 * Time: 12:28
 */
class TestController extends Controller
{
    public function test(Request $request){
//// 初始化一个 cURL 对象
//        $curl = curl_init();
//// 设置你需要抓取的URL
//        curl_setopt($curl, CURLOPT_URL, 'https://api.netease.im/nimserver/user/create.action');
//// 设置header 响应头是否输出
//        curl_setopt($curl, CURLOPT_HEADER, 1);
//// 设置cURL 参数，要求结果保存到字符串中还是输出到屏幕上。
//// 1如果成功只将结果返回，不自动输出任何内容。如果失败返回FALSE
//        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 0);
//// 运行cURL，请求网页
//        $data = curl_exec($curl);
//// 关闭URL请求
//        curl_close($curl);
//// 显示获得的数据
//        print_r($data);
        //post方式
//        $phoneNumber ="13912345678";
//        $message = "testMessage";
//        $curlPost = "phone=".urlencode($phoneNumber)."&message=".$message;
//        $ch=curl_init();
//        curl_setopt($ch,CURLOPT_URL,'https://api.netease.im/nimserver/user/create.action');
//        curl_setopt($ch,CURLOPT_HEADER,0);
//        curl_setopt($ch,CURLOPT_RETURNTRANSFER,0);
////设置是通过post还是get方法
//        curl_setopt($ch,CURLOPT_POST,1);
////传递的变量
//        curl_setopt($ch,CURLOPT_POSTFIELDS,$curlPost);
//        $data = curl_exec($ch);
//        curl_close($ch);
        $url = 'https://api.netease.im/nimserver/user/create.action';
        $data = [];
        $data['accid'] = '29633';
        $data['name'] = 'gery';
        $curl = new IMCurl($url,$data);
        var_dump($curl->getResponse());
        var_dump($curl->getHeader());
    }

    public function boolTest(){
        $a = [
            true,
            false,
            (bool)'false',
            'true',
            'false',
            (string)516515,
            (int)'21df'
        ];
        echo json_encode($a);
    }

    public function redisOriginal(Request $request){
        $user = Redis::get('name');
        echo $user;
//        $redis->connect('120.24.61.9', 6379);
//        //查看服务是否运行
//        echo "Server is running: " . $redis->ping();
//        $user = Redis::get('name');
//
//        var_dump($user);
    }

    public function redisLarval(Request $request){
//        $user = Redis::get('name');
//
//        var_dump($user);
    }

    public function pic(){
//        $file = 'weiboimg/bowen/original/ea38022b90ce1dd45d4152782e83f938.jpeg';
//        $img = new Compress($file);
//        return $img;
    }

    public function server(){
        var_dump($_SERVER);
    }
}